# -*- coding: utf-8 -*-
#===============================================================================
# Koro Business Environment
# Copyright (C) 2008  Antonio Corroppoli
#
#This file is part of Koro BE.
# 
# Koro BE is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# Koro BE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Koro BE; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#===============================================================================

'''
Created on 09/ago/2011

@author: antstud
'''
import datetime
from koro import util
from koro.core import exception
from koro.core.model import IDObject

#===============================================================================
# Agenda
#===============================================================================
class Agenda(IDObject):
    def __init__(self):
        IDObject.__init__(self)
        self.ora='00:00'
        self.data=datetime.date.today()
        self.impegno=''
        self.note=''
        self.fatto=False
    
    def validate(self):
        if not util.to_bool(self.impegno):
            raise exception.KoroInvalidObject("Il campo 'Impegno' è richiesto")
    
    def set_ora(self,ora):
        if ora is None:
            ora='00:00'
        self.ora=ora
    
    def set_data(self,data):
        self.data=util.to_date(data)
    
    def get_data(self):
        return util.to_date(self.data)
    
    def get_ora(self):
        if self.ora is None:
            self.ora='00:00'
        return self.ora
    
    def is_fatto_fmt(self):
        return (self.fatto and 'Si') or 'No'
    
    def _has_ora(self):
        return self.ora and self.ora!='00:00'
    
    def get_scadenza_fmt(self):
        if self.data is None:
            return ''
        #d=self.data_scadenza.strftime("%d/%m/%Y")
        r='{0}'
        if self._has_ora():
            r+=' ore {1}'
        return r.format(util.format_date(self.data),self.ora)
